package com.zit.java.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5Util{
	 public static String md5(String plainText){
	        byte[] sereBytes=null;
	        try {
	            //加密方法
	            sereBytes = MessageDigest.getInstance("md5").digest(plainText.getBytes());
	        } catch (NoSuchAlgorithmException e) {
	            throw new RuntimeException("MD5加密失败");
	        }
	        String result = "";
	        for (byte b : sereBytes) {
	            result = result + Integer.toHexString(b & 0xff);
	            //b & 0xff 是为了取低8位
	        }
	        return result;

	    }
	 
	 public static void main(String[] args) {
		 System.out.println(md5("123456"));
	}
}
